package com.eedi.framework.dict.controller.sys.web;

import com.eedi.framework.dict.controller.sys.vo.type.SysDictTypeResp;
import com.eedi.framework.dict.controller.sys.vo.type.SysDictTypeSimpleResp;
import com.eedi.framework.dict.dal.dataobject.SysDictTypeDO;
import com.eedi.framework.dict.service.SysDictTypeService;
import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.util.object.BeanUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "系统界面 - 字典类型")
@RestController
@RequestMapping("/dict-type")
@Validated
public class SysDictTypeController {

    @Resource
    private SysDictTypeService sysDictTypeService;

//    @PostMapping("/create")
//    @Operation(summary = "创建字典类型")
////    @PreAuthorize("@ss.hasPermission('sys:dict:create')")
//    public CommonResult<String> createDictType(@Valid @RequestBody SysDictTypeSaveReq createReqVO) {
//        String dictTypeId = sysDictTypeService.createDictType(createReqVO);
//        return success(dictTypeId);
//    }

//    @PutMapping("/update")
//    @Operation(summary = "修改字典类型")
////    @PreAuthorize("@ss.hasPermission('sys:dict:update')")
//    public CommonResult<Boolean> updateDictType(@Valid @RequestBody SysDictTypeUpReq updateReqVO) {
//        sysDictTypeService.updateDictType(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除字典类型")
//    @Parameter(name = "sysDictTypeId", description = "编号", required = true, example = "1024")
////    @PreAuthorize("@ss.hasPermission('sys:dict:delete')")
//    public CommonResult<Boolean> deleteDictType(String sysDictTypeId) {
//        sysDictTypeService.deleteDictType(sysDictTypeId);
//        return success(true);
//    }
//
//    @GetMapping("/page")
//    @Operation(summary = "获得字典类型的分页列表")
////    @PreAuthorize("@ss.hasPermission('sys:dict:query')")
//    public CommonResult<PageResult<SysDictTypeResp>> pageDictTypes(@Valid SysDictTypePageReq pageReqVO) {
//        PageResult<SysDictTypeDO> pageResult = sysDictTypeService.getDictTypePage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, SysDictTypeResp.class));
//    }

    @Operation(summary = "/查询字典类型详细")
    @Parameter(name = "sysDictDataType", description = "类型", required = true, example = "xx_xx_xx")
    @GetMapping(value = "/get")
//    @PreAuthorize("@ss.hasPermission('sys:dict:query')")
    public CommonResult<SysDictTypeResp> getDictType(@RequestParam("sysDictDataType") String sysDictDataType) {
        SysDictTypeDO dictType = sysDictTypeService.getDictType(sysDictDataType);
        return success(BeanUtils.toBean(dictType, SysDictTypeResp.class));
    }

    @GetMapping(value = {"/list-all-simple", "simple-list"})
    @Operation(summary = "获得全部字典类型列表", description = "包括开启 + 禁用的字典类型，主要用于前端的下拉选项")
    // 无需添加权限认证，因为前端全局都需要
    public CommonResult<List<SysDictTypeSimpleResp>> getSimpleDictTypeList() {
        List<SysDictTypeDO> list = sysDictTypeService.getDictTypeList();
        return success(BeanUtils.toBean(list, SysDictTypeSimpleResp.class));
    }

}
